package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.BibliotecaItem;
import com.twu.biblioteca.data.BibliotecaItemDAO;
import com.twu.biblioteca.data.User;
import com.twu.biblioteca.exceptions.ItemAlreadyCheckedOutException;

/**
 * Created by florian on 27/12/13.
 */
public abstract class CheckoutController extends ControllerWithItem {
    private final User user;

    public CheckoutController(ScreenControllerFactory controllerFactory, BibliotecaUI ui, BibliotecaItemDAO dao,User user) {
        super(controllerFactory, ui, dao);
        this.user = user;

    }

    @Override
    protected ScreenController handleWithItem(BibliotecaItem item) throws ItemAlreadyCheckedOutException {
        dao.checkoutItem(item, user);
        showSuccessfulCheckoutMessage();
        return controllerFactory.createMainScreenControllerLoggedIn(null);
    }
    @Override
    protected ScreenController handleError() {
        showUnsuccessfulCheckoutMessage();
        return this;
    }

    protected abstract void showSuccessfulCheckoutMessage();
    protected abstract void showUnsuccessfulCheckoutMessage();

}
